package com.akn.mvvmlibrary.adapter

import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

/**
 * dataBinding adapter 子类adapter实现可以使用dataBinding
 * @param BD ViewDataBinding子类
 * @param T 数据实体类
 */
abstract class BaseDataBindingAdapter<T, BD : ViewDataBinding>(@LayoutRes private val layoutResId: Int) :
    BaseQuickAdapter<T, BaseDataBindingHolder<BD>>(layoutResId) {
    override fun convert(holder: BaseDataBindingHolder<BD>, item: T) {
        holder.dataBinding?.setVariable(variableId(), item)
        holder.dataBinding?.let { convert(it, item) }
    }

    abstract fun convert(binding: BD, item: T)

    abstract fun variableId(): Int
}